package edu.xlh.travel.controller.admin;

import edu.xlh.travel.common.Result;
import edu.xlh.travel.pojo.Gallery;
import edu.xlh.travel.service.GalleryService;
import edu.xlh.travel.syslog.annontion.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Controller
@CrossOrigin
@RequestMapping("/gallery")
public class GalleryController {
    @Autowired
    private GalleryService galleryService;

    /*
    * to galleryList page
    * */
    @Log("跳转相册列表页面")
    @RequestMapping("/galleryList")
    public String galleryList() {
        return "admin/gallerymanage/galleryList";
    }

    /*
     * findAllGallery
     * */
    @Log("查询所有的相册")
    @RequestMapping("/findAllGallery")
    @ResponseBody
    public Result findAllGallery() {
        return galleryService.findAll();
    }

    /*
    * to addgallery page
    * */
    @Log("跳转新增相册页面")
    @RequestMapping("/toGalleryAddPage")
    public String toGalleryAddPage(){
        return "admin/gallerymanage/galleryAdd";
    }

    @Log("上传相册")
    @RequestMapping("/uploadFile")
    @ResponseBody
    public Result uploadFile(@RequestParam("file") MultipartFile file) throws Exception {
            return galleryService.uploadFile(file);
    }

    @Log("添加相册")
    @RequestMapping("/addGallery")
    @ResponseBody
    public Result addGallery(@RequestBody Gallery gallery) {
        return galleryService.addGallery(gallery);
    }
}
